;;;; .emacs 8 dic 2018

(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                    (not (gnutls-available-p))))
       (proto (if no-ssl "http" "https")))
  (when no-ssl
    (warn "\
Your version of Emacs does not support SSL connections,
which is unsafe because it allows man-in-the-middle attacks.
There are two things you can do about this warning:
1. Install an Emacs version that does support SSL and be safe.
2. Remove this warning from your init file so you won't see it again."))
  ;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
  (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
  ;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
  (when (< emacs-major-version 24)
    ;; For important compatibility libraries like cl-lib
    (add-to-list 'package-archives (cons "gnu" (concat proto "://elpa.gnu.org/packages/")))))
(package-initialize)



(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(js2-basic-offset 2)
 '(show-paren-mode t))
;;
;; para javascript mode js2-mode
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
;; hace que en lugar de insertar tabs se inserten espacios en blanco
(add-hook 'js2-mode-hook
          '(lambda () (progn
                        (set-variable 'indent-tabs-mode nil))))

;; algunos hooks para web-mode
(defun my-web-mode-hook ()
  "Hooks for Web mode."
  (setq web-mode-markup-indent-offset 2)
  ;;  HTML element offset indentation 
  (setq web-mode-markup-indent-offset 2)
  ;;  CSS offset indentation
  (setq web-mode-css-indent-offset 2)
  ;;  Script/code offset indentation (for JavaScript, Java, PHP, Ruby, Go, VBScript, Python, etc.) 
  (setq web-mode-code-indent-offset 2)
  )

;; asociando archivos con extensiones automaticamente a web-mode
(add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.vue\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.scss\\'" . web-mode))

(setq web-mode-engines-alist
      '(("php"    . "\\.phtml\\'")
        ("blade"  . "\\.blade\\.")
	("vue"  . "\\.vue\\.")
	)
      )

;; agregando autcompletado de ac-js2 a js2-mode
;; (add-hook 'js-mode-hook 'js2-minor-mode)
;; (add-hook 'js2-mode-hook 'ac-js2-mode)
;; ;; js2-mode provides 4 level of syntax highlighting. They are

;; ;;     0 or a negative value means none.
;; ;;     1 adds basic syntax highlighting.
;; ;;     2 adds highlighting of some Ecma built-in properties.
;; ;;     3 adds highlighting of many Ecma built-in functions.
;; (setq js2-highlight-level 3)

; esto hace que los warnings de eso modo no se muestren por defecto
;(js2-mode-hide-warnings-and-errors)

;; activar ac-autocomplete en algunos modos por defecto
(require 'auto-complete)
(global-auto-complete-mode t)
(setq ac-modes '(js2-mode python-mode c-mode lisp-mode javascript-mode lisp-interaction-mode ruby-mode web-mode vue-mode))

(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)


;; python
(add-hook 'python-mode-hook 'jedi:setup)
(setq jedi:complete-on-dot t)

;; para habilitar/desabilitar neotree con F8
(require 'neotree)
(global-set-key [f8] 'neotree-toggle)
;; desactivar autochange root
(setq neo-autorefresh nil)

;; para multiple cursor
(global-set-key (kbd "C-c m c") 'mc/edit-lines)
;; para marcar lineas basadas en 
;; When you want to add multiple cursors not based on continuous lines, but based on keywords in the buffer, use:
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)

;; ruby (auto completado de emacs-robe) (no parece funcionar)
(add-hook 'robe-mode-hook 'ac-robe-setup)

;; probando enh-ruby-mode
;(setq enh-ruby-program "/home/strymsg/.rbenv/versions/2.5.0/bin/ruby") ; so that still works if ruby points to ruby1.8



;; FONTS -------------------------------------
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(default ((t (:inherit nil :stipple nil :background "black" :foreground "gray81" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 90 :width normal :foundry "PfEd" :family "DejaVu Sans Mono"))))
 '(cursor ((t (:background "white"))))
 '(font-lock-comment-face ((t (:foreground "chocolate2"))))
 '(font-lock-doc-face ((t (:foreground "LightSalmon"))))
 '(font-lock-function-name-face ((t (:foreground "#25C96E"))))
 '(font-lock-keyword-face ((t (:foreground "#3A4BE1" :weight bold))))
 '(font-lock-preprocessor-face ((t (:foreground "#A4C441"))))
 '(font-lock-string-face ((t (:foreground "#F33DA2"))))
 '(font-lock-type-face ((t (:foreground "#33EBD4"))))
 '(font-lock-variable-name-face ((t (:foreground "#28A61F" :weight bold))))
 '(js2-function-call ((t (:foreground "#8B9DF4"))))
 '(js2-warning ((t (:underline "#464712"))))
 '(link ((t (:foreground "green1" :underline t))))
 '(markdown-header-face ((t (:inherit font-lock-function-name-face :foreground "#DBCB1C" :weight bold))))
 '(markdown-header-face-1 ((t (:inherit nil :foreground "#DBB931" :weight bold))))
 '(markdown-header-face-2 ((t (:inherit markdown-header-face :foreground "#DFB031"))))
 '(markdown-header-face-3 ((t (:inherit markdown-header-face :foreground "#D4A831"))))
 '(markdown-header-face-4 ((t (:inherit markdown-header-face :foreground "#CA9F2A"))))
 '(markdown-header-face-5 ((t (:inherit markdown-header-face :foreground "#CA9D24"))))
 '(markdown-header-face-6 ((t (:inherit markdown-header-face :foreground "#D4B619"))))
 '(markdown-header-rule-face ((t (:inherit font-lock-function-name-face :foreground "#DBBD1C" :weight bold))))
 '(py-class-name-face ((t (:inherit font-lock-type-face :weight bold))))
 '(py-decorators-face ((t (:inherit font-lock-keyword-face :foreground "#E060CB"))))
 '(py-def-class-face ((t (:inherit font-lock-keyword-face :foreground "#7DE060"))))
 '(py-number-face ((t (:inherit default :foreground "peach puff"))))
 '(py-object-reference-face ((t (:inherit py-pseudo-keyword-face :foreground "#8AE999"))))
 '(py-try-if-face ((t (:inherit font-lock-keyword-face :foreground "#78eede"))))
 '(py-variable-name-face ((t (:inherit default :foreground "#EAE0A5"))))
 '(region ((t (:background "#24396e"))))
 '(web-mode-html-tag-bracket-face ((t (:foreground "#c5ea91")))))

;;
(ac-config-default)

;; hooks para dtrt-ident
;; (add-to-list dtrt-indent-hook-mapping-list
;;   ;; Mode      Syntax     Variable
;;   '((web-mode  js2-mode   web-mode-code-indent-offset))
;;   )

;; ---- fonts por modos ----
;; TODO: Buscar la forma de que el cambio de estilos solo se aplique a los buffers donde estan abiertos los modos


;; javascript
;; (add-hook 'js2-mode (custom-set-faces '(font-lock-keyword-face (( t (:foreground "#7522B7" :weight bold))))))

;; ;; python
;; (add-hook 'python-mode (custom-set-faces '(font-lock-keyword-face (( t (:foreground "#3FB437" :weight bold))))))

;; ;; ruby
;; (add-hook 'ruby-mode-hook (custom-set-faces '(font-lock-keyword-face (( t (:foreground "#D12624" :weight bold))))))

;;--------------------------------------------
